package org.anderground.app.content;

import org.anderground.app.R;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
public class ResourcesActivity extends TabActivity implements
		TabHost.TabContentFactory {

	private static final String FAVOURITE_KEY = "fav";
	private static final String ALL_KEY = "all";
	private ListView favouritesView;
	private ListView allView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		final TabHost tabHost = getTabHost();
		final Resources res = getResources();

		Intent intent = getIntent();
		String action = intent.getAction();
		if (Intent.ACTION_SEARCH.equals(action)) {

		} else {

		}

		// TODO introduce R.strings
		tabHost.addTab(tabHost.newTabSpec(FAVOURITE_KEY).setIndicator(
				res.getText(0, "Favourite")).setContent(this));
		tabHost.addTab(tabHost.newTabSpec(ALL_KEY).setIndicator(
				res.getText(0, "Local")).setContent(this));

		setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onSearchRequested()
	 */
	@Override
	public boolean onSearchRequested() {
		// TODO Auto-generated method stub
		return super.onSearchRequested();
	}

	public View createTabContent(String tag) {
		if (tag.equals(FAVOURITE_KEY)) {
			if (favouritesView == null) {
				favouritesView = new ListView(this);
			}
			favouritesView.setAdapter(new ArrayAdapter<Resource>(this,
					R.layout.resource_row, R.id.star));
			return favouritesView;

		} else if (tag.equals(ALL_KEY)) {
			if (allView == null) {
				allView = new ListView(this);
			}
			allView.setAdapter(new ArrayAdapter<Resource>(this,
					R.layout.resource_row, R.id.star));
			return allView;

		} else {
			return null;
		}
	}

}
